//
// Created by Crestimes on 24-6-2.
//

#ifndef CHARACTER_H
#define CHARACTER_H
#include <ostream>
#include <string>
#include <set>
using namespace std;


// 终结符和非终结符 的类
class Character {
public:
    explicit Character(string name, bool isEnd = false, bool isNullable = false);

    // 重载<运算符用于set的判重(A<B false B<A false -> A==B)
    friend bool operator<(const Character& lhs, const Character& rhs) {
        return lhs.name < rhs.name;
    }

    // 流操作
    friend ostream& operator<<(ostream& os, const Character& obj) {
        string isEndInfo;
        if (obj.isEnd)isEndInfo = "true";
        else isEndInfo = "false";
        string isNullableInfo;
        if (obj.isNullable) isNullableInfo = "true";
        else isNullableInfo = "false";
        os << "{name: " << obj.name
            << " isEnd: " << isEndInfo
            << " isNullable: " << isNullableInfo
            << " firstSet: {";
        for (const auto& c : obj.firstSet) {
            os << c->name << ", ";
        }
        os << "} followSet: {";
        for (const auto& c : obj.followSet) {
            os << c->name << ", ";
        }
        os << "} }";
        return os;
    }

    bool isEnd; // 是否是终结符的标记
    bool isNullable; // 是否可为空
    string name; // 名称或终结符的符号
    set<Character*> firstSet; // First集合
    set<Character*> followSet; // Follow集合
};


#endif //CHARACTER_H
